package app

import (
	"game-server/app/common/request"
	"game-server/app/common/response"
	"game-server/app/services"

	"github.com/gin-gonic/gin"
)

// GamePageList 门户获取游戏列表
// @Summary 门户获取游戏列表
// @Description 门户获取游戏列表
// @Tags 游戏管理
// @Accept json
// @Produce json
// @Param data body request.GameListRequest true "请求参数"
// @Router /gameServer/front/game/list [post]
func GamePageList(c *gin.Context) {
	var form request.GameListRequest
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}

	data, err := services.GameService.GetGameList(form)
	if err != nil {
		response.BusinessFail(c, err.Error())
		return
	}

	response.Success(c, data)
}

// GameClick 游戏点击量+1
// @Summary 游戏点击量+1
// @Description 游戏点击量+1
// @Tags 游戏管理
// @Accept json
// @Produce json
// @Param data body request.GameClickRequest true "请求参数"
// @Router /gameServer/front/game/click [post]
func GameClick(c *gin.Context) {
	var form request.GameClickRequest
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}

	if err := services.GameService.UpdateGameClick(form.ID); err != nil {
		response.BusinessFail(c, err.Error())
		return
	}

	response.Success(c, nil)
}

// GameDetail 门户-id获取游戏详情
// @Summary 门户-id获取游戏详情
// @Description 门户-id获取游戏详情
// @Tags 游戏管理
// @Accept json
// @Produce json
// @Param data body request.GameDetailRequest true "请求参数"
// @Router /gameServer/front/game/detail [post]
func GameDetail(c *gin.Context) {
	var form request.GameDetailRequest
	if err := c.ShouldBindJSON(&form); err != nil {
		response.ValidateFail(c, request.GetErrorMsg(form, err))
		return
	}

	game, err := services.GameService.GetGameDetail(form.ID)
	if err != nil {
		response.BusinessFail(c, err.Error())
		return
	}

	response.Success(c, game)
}
